package com.visionet.jumper.project.sample.utils;

import java.lang.reflect.Method;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Service;
import org.springframework.web.method.HandlerMethod;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;
@Service
public class ValidatorInterceptor extends HandlerInterceptorAdapter {

	public boolean preHandle(HttpServletRequest request,
			HttpServletResponse response, Object handler) throws Exception {
		
		if(handler instanceof HandlerMethod){
			HandlerMethod handlerMethod = (HandlerMethod) handler;
			Method method = handlerMethod.getMethod();
			ValidatedData annotation = method.getAnnotation(ValidatedData.class);
			//如果没有@ValidatedData注解则跳过拦截  
			if(annotation!=null){
				System.out.println("你遇到了：@ValidatedData");
				
				/*String message = ValidatorHelperUtils.validator(result);
				if(message.equals("success")){
					
				}else{
					return false;
				}*/
			}
		}
		// 没有注解通过拦截
		return true;
	}

	public void postHandle(HttpServletRequest request,
			HttpServletResponse response, Object handler,
			ModelAndView modelAndView) throws Exception {
		
		System.out.println("ControllerInterceptor.postHandle()");
	}

	public void afterCompletion(HttpServletRequest request,
			HttpServletResponse response, Object handler, Exception ex)
			throws Exception {
		
		System.out.println("ControllerInterceptor.afterCompletion()");
	}

}
